package com.vvlive.caibao.smartcity.base;

import com.vvlive.caibao.smartcity.bean.Dept;
import com.vvlive.caibao.smartcity.bean.MeetingRoom;
import com.vvlive.caibao.smartcity.utils.MeetingsController;

import java.util.List;

/**
 * Created by zhj on 2015/10/23.
 */
public class GetDeptInfo {

    private MeetingsController mController;

    private List<Dept> mDepts;
    private List<MeetingRoom> mRooms;

    private OnLoadFinishListener mListener;

    public GetDeptInfo() {
        mController = new MeetingsController();
    }

    public void load(OnLoadFinishListener loadFinishListener) {
        mListener = loadFinishListener;
        mController.fetchDepartments(new DeptsListGet());
    }

    final class DeptsListGet extends ListHttpCallBack<Dept> {

        @Override
        public void onSuccess(List<Dept> list) {
            mDepts = list;
            mController.fetchMeetingRooms(new RoomListGet());
        }

        @Override
        public void onError(int errCode, String str) {
            if (mListener != null) {
                mListener.onLoadError(errCode, str);
            }
        }
    }

    final class RoomListGet extends ListHttpCallBack<MeetingRoom> {

        @Override
        public void onSuccess(List<MeetingRoom> list) {
            mRooms = list;
            if (mListener != null && mDepts != null && mRooms != null) {
                mListener.onLoadFinish(mDepts, mRooms);
            }
        }

        @Override
        public void onError(int errCode, String str) {
            if (mListener != null) {
                mListener.onLoadError(errCode, str);
            }
        }
    }

    public interface OnLoadFinishListener {

        void onLoadFinish(List<Dept> depts, List<MeetingRoom> rooms);

        void onLoadError(int errCode, String str);
    }


}
